/* 
 * File:   CWindow.cpp
 * Author: root
 * 
 * Created on March 24, 2012, 7:36 PM
 */

#include "CWindow.h"

//------------------------------------------------------------------------------
// Window Constructor
//------------------------------------------------------------------------------
CWindow::CWindow()
{
    m_gtkWindow = NULL;
    m_gtkWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    ASSERT(m_gtkWindow != NULL);
}

//------------------------------------------------------------------------------
// Window Constructor
//------------------------------------------------------------------------------
CWindow::CWindow(LPCTSTR szTitle)
{
    CWindow();
    gtk_window_set_title(GTK_WINDOW(m_gtkWindow), szTitle);
}

//------------------------------------------------------------------------------
// Window destructor
//------------------------------------------------------------------------------
CWindow::~CWindow()
{
    delete m_gtkWindow;
}

//------------------------------------------------------------------------------
// Show Window
//------------------------------------------------------------------------------
VOID CWindow::ShowWindow()
{
    ASSERT(m_gtkWindow != NULL);
    gtk_widget_show(m_gtkWindow);
}

//------------------------------------------------------------------------------
// Set Window title
//------------------------------------------------------------------------------
VOID CWindow::SetWindowTitle(LPCTSTR szTitle)
{
    ASSERT(m_gtkWindow != NULL);
    gtk_window_set_title(GTK_WINDOW(m_gtkWindow), szTitle);
}

//------------------------------------------------------------------------------
// Set Window Position
//------------------------------------------------------------------------------
VOID CWindow::SetWindowPosition(INT x, INT y)
{
    ASSERT(m_gtkWindow != NULL);
    gtk_window_move(GTK_WINDOW(m_gtkWindow), x, y);
}

//------------------------------------------------------------------------------
// Set Window Size
//------------------------------------------------------------------------------
VOID CWindow::SetWindowSize(INT height, INT width)
{
    ASSERT(m_gtkWindow != NULL);
    gtk_window_resize(GTK_WINDOW(m_gtkWindow), width, height);
}

//------------------------------------------------------------------------------
// Set If Window is resizeable
//------------------------------------------------------------------------------
VOID CWindow::SetResizeable(BOOL bResizeable)
{
    ASSERT(m_gtkWindow != NULL);
    gtk_window_set_resizable(GTK_WINDOW(m_gtkWindow), bResizeable);
}

//------------------------------------------------------------------------------
// Hide Window
//------------------------------------------------------------------------------
VOID CWindow::HideWindow()
{
    ASSERT(m_gtkWindow != NULL);
    gtk_widget_hide(m_gtkWindow);
}

//------------------------------------------------------------------------------
// Set Background Color
//------------------------------------------------------------------------------
VOID CWindow::SetBgColor(USHORT unRed, USHORT unGreen, USHORT unBlue)
{
    ASSERT(m_gtkWindow != NULL);
    
    GdkColor bgColor;
    bgColor.red         = unRed;
    bgColor.green       = unGreen;
    bgColor.blue        = unBlue;
    
    gtk_widget_modify_bg(m_gtkWindow, GTK_STATE_NORMAL, &bgColor);
}

//------------------------------------------------------------------------------
// If the Window is Closed the application exits
//------------------------------------------------------------------------------
VOID CWindow::SetExitAppOnClose(BOOL bExitApp)
{
    ASSERT(m_gtkWindow != NULL);
    
    if (bExitApp)
    {
        gtk_signal_connect(GTK_OBJECT (m_gtkWindow), "destroy",
                    GTK_SIGNAL_FUNC (gtk_exit), NULL);
    }
    else
    {
        gtk_signal_disconnect_by_func(GTK_OBJECT (m_gtkWindow),
                GTK_SIGNAL_FUNC (gtk_exit), NULL);
    }
}

//------------------------------------------------------------------------------
// Center the window in the center of the screen
//------------------------------------------------------------------------------
VOID CWindow::CenterWindow()
{
    ASSERT(m_gtkWindow != NULL);
    gtk_window_set_position(GTK_WINDOW (m_gtkWindow), GTK_WIN_POS_CENTER);
}

//------------------------------------------------------------------------------
// Show or hide window Decorations
//------------------------------------------------------------------------------
VOID CWindow::SetDecorations(BOOL bShow)
{
    ASSERT(m_gtkWindow != NULL);
    gtk_window_set_decorated(GTK_WINDOW (m_gtkWindow), bShow);
}

//------------------------------------------------------------------------------
// Set Window transparency
//------------------------------------------------------------------------------
VOID CWindow::SetWindowTransparency()
{
    GdkDrawable gdkShape = 
    gtk_widget_shape_combine_mask(m_gtkWindow, , 0, 0);
}
